/*!
	This module defines API function to make the program running with
	real-time ability base on POSIX sched.h

	Company: PI Electronic (H.K.) Ltd
	Author : Terence
	Date: 13 Jan 2015

	v1: Revise stack prefault function // Terence on 26 Aug 2015

*/
#ifndef __REALTIME_H__
#define __REALTIME_H__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE // neccessaru for gcc complier to recognize the sched.h library
#endif

#include "stdlib.h"
#include "stdio.h"
#include "string.h" // needed for memset
#include "sched.h"
#include "sys/mman.h"
#include "time.h"
#include "pthread.h"
#include "sys/time.h"	// needed for getrusage
#include "sys/resource.h"	// needed for getrusage
#include "limits.h"
#include "unistd.h"     // needed for sysconf(int name);
#include "malloc.h"
#include "time_fun.h"	// User defined
#include "errno.h"


void set_dedicated_cpu(int cpuid);
void set_dedicated_cpu_thread(pthread_t tid, int cpuid);
//! set the realtime priority to the process
/*!
	input: 
		pid: process ID, can get it by calling getpid()
		priority: range from 0-99,
				  99 is he most realtime priority, 0 is the lowest   
*/
void make_realtime (int pid, int priority);
//! set the realtime priority to the thread
/*!
	input: 
		tid: thread ID
		priority: range from 0-99,
				  99 is he most realtime priority, 0 is the lowest   
*/
void make_realtime_thread(pthread_t tid, int priority);

//!	Stack prefault function
/*!
	input:
		max_safe_stack: size of prefault stack in byte
*/
void stack_prefault(int max_safe_stack) ;


// lock the physical memory page to prevent stack prefualt // Add by Terence on 26 Aug 2015
void lock_mem_page(void);

// Check the stack prefault times // Added by Terence on 26 Aug 2015
void pagefault_count(const char* logtext);

#endif

